<?php
class TagsController extends AdminAppController
{
    public $uses = array('Admin.Tag');

    public $paginate = array(
        'limit' => 25,
        //'conditions' => array('Tag.link_visible' => 1),
        //'order' => array(
        //    'Tag.link_rating' => 'desc',
        //),
    );

    public function index()
    {
        $data = $this->paginate('Tag');
     
        $this->set(compact('data'));

        if ($this->request->is('get')) {
        } else {
            try {
                $this->Tag->save($this->request->data);
                $this->redirect(array('action' => 'index'));
                $this->Session->setFlash(__('The Tag has been saved'));
            } catch (Exception $e) {
                $validationErrors = $this->Tag->validationErrors;
                $this->set(compact('validationErrors'));
                $this->Session->setFlash($e->getMessage());
            }
        }
    }


    public function add()
    {
        if ($this->request->is('post')) {
            try {
                debug($this->request->data);
                $this->Tag->saveLink($this->request->data['Link']);
                $this->redirect(array('action' => 'index'));
                $this->Session->setFlash(__('The Tag has been saved'));
            } catch (Exception $e) {
                $validationErrors = $this->Tag->validationErrors;
                $this->set(compact('validationErrors'));
                $this->Session->setFlash($e->getMessage());
            }
        }
    }

    public function edit($id=null)
    {
        $info = $this->Tag->findByTagId($id);
        if ($this->request->is('get')) {
            $this->request->data = $info;
        } else {
            try {
                $isUpdate = true;
                debug($this->request->data);
                $this->Tag->save($this->request->data);
                $this->redirect(array('action' => 'index'));
                $this->Session->setFlash(__('The Tag has been saved'));
            } catch (Exception $e) {
                $validationErrors = $this->Tag->validationErrors;
                $this->set(compact('validationErrors'));
                $this->Session->setFlash($e->getMessage());
            }
        }
    }
}
